package it.scambiocorse.dao;

import it.scambiocorse.model.ServizioType;
import it.scambiocorse.utils.Utils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;

import org.springframework.jdbc.core.PreparedStatementCreator;

import com.mysql.jdbc.Statement;

public class PSC implements PreparedStatementCreator {
	
private ServizioType s;
private String sql;

PSC () {}
PSC (ServizioType s, String sql) {
	this.s = s;
	this.sql = sql;
}
PSC (ServizioType s) {
	this.s = s;
}

	public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
		String sql = "insert into serv_tab (" +
				  "id_serv_user," +
				  "id_user_inse," +
				  "id_area," +
				  "id_cliente," +
				  "id_sorgente," +
				  "id_autista," +
				  "deco_tipo_serv," +
				  "citta," +
				  "pick_up," +
				  "drop_off," +
				  "dataora," +
				  "data_inse," +
				  "veicolo," +
				  "pax," +
				  "prezzo," +
				  "is_ok," +
				  "note," +
				  "pick_tk," +
				  "drop_tk," +
				  "id_user_exec," +
				  "dare," +
				  "avere," +
				  "data_fine," +
				  "commissione," +
				  "ora_fine," +
				  "volo)" +

				  	" values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
		
		
		PreparedStatement ps = connection.prepareStatement(sql,Statement.RETURN_GENERATED_KEYS);
		ps.setInt(1, s.getIdServUser());
		ps.setInt(2, s.getIdUserInse());
		ps.setInt(3, s.getArea().getIdArea());
		ps.setInt(4, s.getCliente().getIdCliente());
		ps.setInt(5, s.getSorgente().getIdSorgente());
		ps.setInt(6, s.getAutista().getIdAutista());
		ps.setInt(7, s.getTipoServizio());
		ps.setString(8, s.getCitta());
		ps.setString(9, s.getPickUp());
		ps.setString(10, s.getDropOff());
		ps.setTimestamp(11,s.getDataora());
		ps.setTimestamp(12,Utils.getSysDate());
		ps.setString(13, s.getVeicolo());
		ps.setInt(14, s.getPax());
		ps.setDouble(15, s.getPrezzo());
		ps.setInt(16, 1);
		ps.setString(17, s.getNote());
		ps.setString(18, s.getPickUpToken());
		ps.setString(19, s.getDropOffToken());
		ps.setInt(20, s.getIdUserExec());
		ps.setDouble(21, s.getDare());
		ps.setDouble(22, s.getAvere());
		ps.setTimestamp(23,s.getDataFine());
		ps.setDouble(24, s.getCommissione());
		ps.setTimestamp(25, s.getOraFine());
		ps.setString(26, s.getVolo());

		
		
	return ps;
	}
}
